import requests

if __name__ == '__main__':
    # 定义主机路径
    url = 'http://127.0.0.1:6688/'
    # 用户登录
    usr1 = requests.post(url+'api/account/login',json={'account':'13939084802','password':'admin123','client':2})
    print(usr1.text)
    # 提取token参数
    token = usr1.json()['data']['token']
    print(token)

    #  搜索商品列表
    ssgoods = requests.get(url+'api/goods/getGoodsList',params={'category_id':'1'})
    print(ssgoods.text)

    # 查看商品详情
    spxq = requests.get(url+'api/goods/getGoodsDetail',params={'id':'1'})
    print(spxq.text)

    # 添加商品到购物车
    addgoods = requests.post(url+'api/cart/add',data={'item_id':1,'goods_num':1},headers={'token':token})
    print(addgoods.text)

    #   提交订单
    order ={
                                                  "action": "submit",
                                                  "delivery_type": 1,
                                                  "goods": [
                                                    {
                                                      "item_id": 2,
                                                      "num": 5
                                                    }
                                                  ],
                                                  "use_integral": 0,
                                                  "address_id": "",
                                                  "remark": "",
                                                  "type": "cart"
                                                }
    add = requests.post(url+'api/order/buy',json=order,headers={'token':token})
    print(add.text)